package com.ruoyi.web.controller.home;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.javid.service.ToolsExpiredWarnningService;
import com.ruoyi.javid.vo.ExpiredWarnningForm;
import com.ruoyi.javid.vo.ExpiredWarnningList;
import com.ruoyi.web.service.ToolsService;
import com.ruoyi.web.vo.CreatePicForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/tools")
public class ToolsController {

    @Autowired
    ToolsService toolsService;
    @Autowired
    ToolsExpiredWarnningService toolsExpiredWarnningService;

    @PreAuthorize("@ss.hasPermi('monitor:online:list')")
    @PostMapping("/createPic")
    public AjaxResult createPic(@Validated @RequestBody CreatePicForm createPicForm) {
        if (createPicForm.getType().equals("zhe")) {
            String s = toolsService.createPic(createPicForm);
            if (s.contains("失败")) {
                log.error(s);
                return AjaxResult.error("操作失败！");
            } else {
                return AjaxResult.success("成功", s);
            }
        } else {
            return AjaxResult.error("暂不支持此类型");
        }
    }

    @PreAuthorize("@ss.hasPermi('monitor:online:list')")
    @PostMapping("/expiredWarnning")
    public AjaxResult expiredWarnning(@Validated @RequestBody ExpiredWarnningForm expiredWarnning) {
        return toolsExpiredWarnningService.expiredWarnning(expiredWarnning);
    }

    @PreAuthorize("@ss.hasPermi('monitor:online:list')")
    @GetMapping("/expiredWarnning/list")
    public AjaxResult expiredWarnningList() {
        List<ExpiredWarnningList> list = toolsExpiredWarnningService.expiredWarnningList();
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('monitor:online:list')")
    @GetMapping("/expiredWarnning/delete")
    public AjaxResult expiredWarnningDelete(@RequestParam("id") Integer id) {
        return toolsExpiredWarnningService.expiredWarnningDelete(id);
    }

}
